//
//  SuperTempVc.m
//  TH_HM_CombineSDKTestDemo
//
//  Created by   on 2020/11/19.
//  Copyright © 2020 None. All rights reserved.
//

#import "SuperTempVc.h"

@interface SuperTempVc ()
@property(copy, nonatomic)void(^backBlk)(void);
@property(copy, nonatomic)void(^rightBlk)(void);

@property(weak, nonatomic)UIButton *rightCustomBtn;

@end

@implementation SuperTempVc

- (void)viewDidLoad {

    
    
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
}

#pragma mark -- navbar style
-(void)customNavStyleNormal:(NSString *)centerTitle BackBlk:( void(^ __nullable)(void))backBlk
{
    //navbar 背景
    
    [self customCenterTitle:centerTitle];
    
    //左按钮
    CGFloat bt_w = 50.0f;
    UIButton  * leftCustomBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 60, bt_w, 44)];
    [leftCustomBtn addTarget:self action:@selector(backBtn:) forControlEvents:UIControlEventTouchUpInside];
    [leftCustomBtn setTitle:@"Back" forState:UIControlStateNormal];
//    [leftCustomBtn setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];

    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftCustomBtn];
    if (backBlk != nil) {
        UIImage *btnArrowImg = [UIImage imageNamed:@"back_arrow"];
        [leftCustomBtn setImage:btnArrowImg forState:UIControlStateNormal];
        CGFloat imageV_w = btnArrowImg.size.width;
        leftCustomBtn.imageEdgeInsets = UIEdgeInsetsMake(0, imageV_w - bt_w, 0, 0);
    }
    
    self.navigationItem.leftBarButtonItem = leftItem;
    self.backBlk = backBlk;
}

-(void)customCenterTitle:(NSString *)centerTitle
{
    if (centerTitle == nil) {
        return;
    }
    UINavigationBar *navBar = self.navigationController.navigationBar;
    if (!navBar) {
        return;
    }
    navBar.tintColor = [UIColor whiteColor];
    //    self.title = centerTitle;
    //    [self gradientBackGround]; //渐变色背景
    //title
    UILabel  *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 250, 44)];
    titleLabel.font = [UIFont fontWithName:@"ArialMT" size:19.0f];
//    [titleLabel setTextColor:[UIColor darkTextColor]];
    titleLabel.text = centerTitle;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
    
    self.navigationItem.titleView = titleLabel;
}

-(void)customNavRightBtn:(NSString *)rightBtnTitle BackBlk:( void(^ __nullable)(void))rightBlk
{
    
    //左按钮
    CGFloat bt_w = 50.0f;
    UIButton  * rightCustomBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, bt_w, 44)];
//    [rightCustomBtn setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
    [rightCustomBtn setTitle:rightBtnTitle forState:UIControlStateNormal];
    [rightCustomBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [rightCustomBtn.titleLabel setLineBreakMode:NSLineBreakByClipping];
    rightCustomBtn.titleLabel.numberOfLines = 2;
    [rightCustomBtn addTarget:self action:@selector(rightBtnCLick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:rightCustomBtn];

    self.navigationItem.rightBarButtonItem = leftItem;
    self.rightCustomBtn = rightCustomBtn;
    self.rightBlk = rightBlk;
}

-(void)changeNavRightBtnTitle:(NSString *)rightTitle
{
    [self.rightCustomBtn setTitle:rightTitle forState:UIControlStateNormal];
}

#pragma mark --navbar按键响应
- (void)backBtn:(UIButton *)btn {
    if (self.backBlk) {
        self.backBlk();
    }
    
}

- (void)rightBtnCLick:(UIButton *)btn {
    if (self.rightBlk) {
        self.rightBlk();
    }
    
}


@end
